package com.gitee.wsl.model.process.call

import com.gitee.wsl.model.process.response.ProcessResponse
import com.gitee.wsl.reflect.TypeInfo
import kotlin.reflect.KClass

/**
 * Exception representing that the response payload has already been received.
 */

 class DoubleReceiveException(call: ProcessClientCall) : IllegalStateException() {
    override val message: String = "Response already received: $call"
}

/**
 * Exception representing fail of the response pipeline
 * [cause] contains origin pipeline exception
 */
@Suppress("KDocMissingDocumentation", "unused")
 class ReceivePipelineException(
    val request: ProcessClientCall,
    val info: TypeInfo,
    override val cause: Throwable
) : IllegalStateException("Fail to run receive pipeline: $cause")

/**
 * Exception represents the inability to find a suitable transformation for the received body from
 * the resulted type to the expected by the client type.
 *
 * You can read how to resolve NoTransformationFoundException at [FAQ](https://ktor.io/docs/faq.html#no-transformation-found-exception)
 */
 class NoTransformationFoundException(
    processResponse: ProcessResponse,
    from: KClass<*>,
    to: KClass<*>
) : UnsupportedOperationException() {
    override val message: String = """
        Expected response body of the type '$to' but was '$from'
        In response from `${processResponse}`
        Response status `${processResponse}`
       
        You can read how to resolve NoTransformationFoundException at FAQ: 
        https://ktor.io/docs/faq.html#no-transformation-found-exception
    """.trimIndent()
}